package com.meixiang.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.entity.account.AccountMessageList;
import com.meixiang.recyclerview.OnItemClick;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 账户消息
 */
public class AccountMessageAdapter extends RecyclerView.Adapter<AccountMessageAdapter.MyViewHolder> {


    private Context context;
    List<AccountMessageList> mList = new ArrayList<>();

    public AccountMessageAdapter(Context context) {
        this.context = context;
    }


    public void addAll(List<AccountMessageList> mList) {
        this.mList.addAll(mList);
        this.notifyDataSetChanged();
    }

    public void clearData() {
        mList.clear();
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        MyViewHolder myViewHolder = new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.list_item_account_message, parent, false));
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int pos = holder.getLayoutPosition();
                onItemClickListener.onItemClick(holder.itemView, pos);
            }
        });
//        if (mList != null) {
//            AccountMessage mData = mList.get(position);
//            holder.mIvPicture.setImageResource(R.mipmap.wuliu);
//            GlideHelper.showImage(context, mData.getMessageImage(), R.drawable.image_default_white_bg, holder.mIvPicture);
//            holder.mTvMsgTitle.setText(mData.getTitle());
//            holder.mTvMsgTime.setText(mData.getCreateTime());
//            holder.mTvMsgContent.setText(mData.getDescription());
//        }
        if (position == 0) {
            holder.mIvPicture.setImageResource(R.mipmap.kefus);
            holder.mTvMsgTitle.setText("客服消息");
//            holder.mTvMsgTime.setText("3月18日");
            holder.mTvMsgContent.setText("点击查看您与客服的沟通记录");
        }
        if (position == 1) {
            holder.mIvPicture.setImageResource(R.mipmap.wuliu);
            holder.mTvMsgTitle.setText("物流助手");
//            holder.mTvMsgTime.setText("3月18日");
//            holder.mTvMsgContent.setText("您有一笔订单已发货");
        }
        if (position == 2) {
            holder.mIvPicture.setImageResource(R.mipmap.yuyue_msg);
            holder.mTvMsgTitle.setText("预约消息");
//            holder.mTvMsgTime.setText("2月26日");
//            holder.mTvMsgContent.setText("您预约了明天（2月27日）预约了美容项目，别忘...");
        }

    }

    @Override
    public int getItemCount() {

        return 3;
//        return mList.size();
    }

    public OnItemClick onItemClickListener;

    public void setOnItemClickListener(OnItemClick onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }


    class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.iv_picture)
        ImageView mIvPicture;
        @Bind(R.id.tv_msg_title)
        TextView mTvMsgTitle;
        @Bind(R.id.tv_msg_time)
        TextView mTvMsgTime;
        @Bind(R.id.tv_msg_content)
        TextView mTvMsgContent;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}